{extend name="public/base" /}
{block name="title"}站点管理{/block} {block name="main"}
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" action="" method="GET">
            <div class="layui-inline">
                <label class="layui-form-label">关键字</label>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="keyword" value="{$keyword}" class="layui-input searchVal" placeholder="请输入搜索的内容" />
                    </div>
                </div>
            </div>
            
            <div class="layui-inline">
                <label class="layui-form-label layui-col-md4">状态</label>
                <div class="layui-input-inline layui-col-md4">
                    <select name="status">
                        <option value="" {$status==''? 'selected': ''}>请选择</option>
                        <option value="1" {$status==1? 'selected': ''}>正常</option>
                        <option value="2" {$status==2? 'selected': ''}>关闭</option>
                    </select>
                </div>
            </div>
            <button class="layui-btn search_btn" id="savebtn" lay-submit="">搜索</button>
            <div class="layui-inline">
                <a href="/site/site/add" class="layui-btn layui-btn-normal addNews_btn">添加站点</a>
            </div>
        </form>
    </blockquote>
    <form class="layui-form">
        <table cellspacing="0" cellpadding="0" border="0" style="width: 100%;" class="layui-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>站点名称</th>
                    <th>联系人</th>
                    <th>联系方式</th>
                    <th>地址</th>
                    <th>添加时间</th>
                    <th style="width: 80px;">状态</th>
                    <th class="layui-table-fixed layui-table-fixed-r">操作</th>
                </tr>
            </thead>
            <tbody>
                {if condition="$data['msg']"}
                    <tr class="td_center"><td colspan="10">{$data['msg']}</td></tr>
                {/if}
                {volist name="data['list']" id="item"}
                <tr class="nodelist depth01">
                    <td class="td_left">
                        <div class="layui-table-cell ">{$item['siteid']}</div>
                    </td>
                    <td class="td_left">
                        <div class="layui-table-cell ">{$item['name']}</div>
                    </td>
                    <td class="td_left">
                        <div class="layui-table-cell ">{$item['contactname']}</div>
                    </td>
                    <td class="td_left">
                        <div class="layui-table-cell ">{$item['contacttel']}</div>
                    </td>
                    <td class="td_left">
                        <div class="layui-table-cell ">{$item['address']}</div>
                    </td>
                    <td class="td_left">
                        <div class="layui-table-cell ">{$item['addtime']?date("Y-m-d H:i:s",$item['addtime']):''}</div>
                    </td>
                    <td>
                        <div class="layui-table-cell layui-inline" style="height:auto;">
                            <input lay-filter="status" type="checkbox" {$item[ 'status']==1? 'checked': ''} data-id="{$item['siteid']}" lay-skin="switch" lay-text="正常|关闭">
                        </div>
                    </td>
                    <td class="td_center">
                        <a href="/site/site/edit/siteid/{$item['siteid']}" class="editNode layui-btn layui-btn-xs">编辑</a>
                    </td>
                </tr>
                {/volist}
            </tbody>
        </table>
    </form>
{$showpage|raw} 

{/block} {block name="script"}
<script>
    layui.use(['form'], function (form) {
        form.on('switch(status)', function (data) {
            var id = $(data.elem).data("id");
            var ischecked = data.elem.checked;
            $.post("/site/site/editstatus",{siteid:id},function(ret){
                if(ret.code!=1){
                    layer.msg(ret.msg);
                    if(ischecked){
                        $(data.elem).prop("checked",false);
                        $(data.othis).removeClass("layui-form-onswitch").find("em").text("关闭");
                    }else{
                        $(data.elem).prop("checked",true);
                        $(data.othis).addClass("layui-form-onswitch").find("em").text("正常");
                    }
                }
            })
            return false;
        });
    });
</script> {/block}